package com.ews.onlineexchange.service.startup;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;

import com.alicom.mns.tools.DefaultAlicomMessagePuller;


@Singleton
@Startup
public class SmsListenerBean {
	private static final String ACCESS_KEY_ID = "LTAIheELjArTrq0L";
	private static final String ACCESS_SECRET = "6DDZ2e4nQaVI7zgkP5sb8kNvOcjco8";
	private static final String QUEUE_NAME = "Alicom-Queue-1826859704005129-SmsReport";
	private static final String MESSAGE_TYPE = "SmsReport";
	
	@PostConstruct
	public void init() {
		DefaultAlicomMessagePuller puller=new DefaultAlicomMessagePuller();
		//设置异步线程池大小及任务队列的大小，还有无数据线程休眠时间
		puller.setConsumeMinThreadSize(6);
		puller.setConsumeMaxThreadSize(16);
		puller.setThreadQueueSize(200);
		puller.setPullMsgThreadSize(1);
		//和服务端联调问题时开启,平时无需开启，消耗性能
		puller.openDebugLog(false);
		/*
		* TODO 将messageType和queueName替换成您需要的消息类型名称和对应的队列名称
		*云通信产品下所有的回执消息类型:
		*1:短信回执：SmsReport，
		*2:短息上行：SmsUp
		*3:语音呼叫：VoiceReport
		*4:流量直冲：FlowReport
		*/
//		String messageType="messageType";//此处应该替换成相应产品的消息类型
//		String queueName="queueName";//在云通信页面开通相应业务消息后，就能在页面上获得对应的queueName,格式类似Alicom-Queue-xxxxxx-SmsReport
		try {
			System.out.println("进入短信监听");
			puller.startReceiveMsg(ACCESS_KEY_ID,ACCESS_SECRET, MESSAGE_TYPE, QUEUE_NAME, new SmsMessageListener());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

	
	
}
